<?php
$logger->info('Start=======================================movie details page=======================================Start');
$logger->info('Memory Usage: ' . memory_get_usage());
/*
 * 'destination' => 'movie',
 * 'page' => 'details',
 * 'key' => '5',
 */

$xmlMetaData = plexGetMetadata($_GET['key']);

$thumbOverlay = $homePath . '/images/movies/details/';
?>
<html>
    <head>
        <link rel="StyleSheet" type="text/css" href="<?php echo $homePath . "/css/details.css.php" ?>"/>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title><?php echo $xmlMetaData->Video['title'] ?></title>
        <script type="text/javascript">
            <!--
            var sPlotLong = "<?php echo $xmlMetaData->Video['summary'] ?>";
            var sTitleLong = "<?php echo $xmlMetaData->Video['title'] ?>";
            var fWatch = true;
            var fTVplaylist= true;
            -->
        </script>
        <script type="text/javascript">
            <!--
            asPlotPart.push("<?php echo substr($xmlMetaData->Video['summary'], 0, 268) ?>...");
            -->
        </script>
        <script type="text/javascript">
            <!--
            asPlotPart.push("<?php echo substr($xmlMetaData->Video['summary'], 268) ?>");
            -->
        </script>
        <script type="text/javascript">
            <!--
            // series config vars
            var iPage = 1;
            var iPageMax = asPlotPart.length - 1;
            var iWatch = 0;
            var iWatchMax = asWatchbar.length - 1;
            var helpx = ' ';
            var helpy = new Array('0');
            var asFile = new Array('0');
            var imgId= ' ';
            var imgChangeOn = ' ';
            var imgChangeOff = ' ';
            var imgPrefix = 'pictures/gtmod/';
            var x = 0;
            var fLowlist =true;

            clickLeft = function ()
            {
                if (iWatchMax != 0)
                {
                    imgId = 'img' + asWatchbar[iWatch];
                    imgChangeOff = imgPrefix + imgId + 'off.png';
                    document.getElementById(imgId).setAttribute("src",imgChangeOff);
                    if (iWatch == 0) {iWatch = iWatchMax;}
                    else {iWatch = iWatch - 1;}
                    imgId = 'img' + asWatchbar[iWatch];
                    imgChangeOn = imgPrefix + imgId + 'on.png';
                    document.getElementById(imgId).setAttribute("src",imgChangeOn);
                    iPage = 1;
                    showPage();
                }
            },

            clickRight = function ()
            {
                if (iWatchMax != 0)
                {
                    imgId = 'img' + asWatchbar[iWatch];
                    imgChangeOff = imgPrefix + imgId + 'off.png';
                    document.getElementById(imgId).setAttribute("src",imgChangeOff);
                    if (iWatch == iWatchMax) {iWatch = 0;}
                    else {iWatch = iWatch + 1;}
                    imgId = 'img' + asWatchbar[iWatch];
                    imgChangeOn = imgPrefix + imgId + 'on.png';
                    document.getElementById(imgId).setAttribute("src",imgChangeOn);
                    iPage = 1;
                    showPage();
                }
            },

            showPage = function()
            {
                helpx = asWatchbar [iWatch];
                if (helpx == 'Plot')
                {
                    iPageMax = asPlotPart.length - 1;
                    helpy[0] = asPlotPart[iPage];
                    asFile = sFileURL.split(",");
                    helpy[1] = asFile[0];
                    helpy[2] = asFile[1];
                }
                else if (helpx == 'Bonus')
                {
                    iPageMax = asBonus.length - 1;
                    helpy = asBonus[iPage].split(",");

                }
                else if (helpx == 'Extra')
                {
                    iPageMax = asExtra.length - 1;
                    helpy = asExtra[iPage].split(",");

                }
                else if (helpx == 'Trailer')
                {
                    iPageMax = asTrailer.length - 1;
                    helpy = asTrailer[iPage].split(",");

                }
                else if (helpx == 'Multi')
                {
                    iPageMax = asMultiPart.length - 1;
                    helpy = asMultiPart[iPage].split(",");

                }


                document.getElementById('play').removeAttribute('vod');
                document.getElementById('play').removeAttribute('zcd');

                if (helpy[2] == 'playlist') 
                {
                    var newAttribute = document.createAttribute("vod");
                    newAttribute.nodeValue = "playlist";
                    document.getElementById('play').setAttributeNode(newAttribute);

                }
                else if (helpy[2] == 'zcd')
                {
                    var newAttribute = document.createAttribute("zcd");
                    newAttribute.nodeValue = "2";
                    document.getElementById('play').setAttributeNode(newAttribute);

                }
                else if (helpy[2] == 'vod')
                {
                    var newAttribute = document.createAttribute("vod");
                    newAttribute.nodeValue = "";
                    document.getElementById('play').setAttributeNode(newAttribute);
                }

                document.getElementById('gtPlot').firstChild.nodeValue = helpy[0];
                document.getElementById('pages').firstChild.nodeValue = ' '+ iPage + ' / ' + iPageMax + ' ';
                document.getElementById('play').setAttribute("href",helpy[1]);
            },

            pageDown = function()
            {
                if (iPageMax != 1)
                {
                    if (iPage == iPageMax) {iPage = 1;}
                    else {iPage = iPage + 1;}
                    showPage();
                }
            },

            pageUp = function()
            {
                if (iPageMax != 1)
                {
                    if (iPage == 1)
                    {
                        iPage = iPageMax;
                    }
                    else 
                    {
                        iPage = iPage - 1;
                    }
                    showPage();
                }
            },
            toggleWatchbar = function()
            {
                if (fWatch == false) 
                {
                    document.getElementById('watchbar').setAttribute("class","");
                    fWatch = true;
                }
                else 
                {
                    document.getElementById('watchbar').setAttribute("class","hidden");
                    fWatch = false;
                }
            },

            toggleLowlist = function()
            {
                if (fLowlist == false) 
                {
                    document.getElementById('lowlist').setAttribute("class","");
                    document.styleSheets[1].cssRules[3].style.visibility='visible';
                    document.styleSheets[1].cssRules[5].style.visibility='visible';
                    document.styleSheets[1].cssRules[7].style.visibility='visible';
                    fLowlist = true;
                }
                else 
                {
                    document.getElementById('lowlist').setAttribute("class","hidden");
                    document.styleSheets[1].cssRules[3].style.visibility='hidden';
                    document.styleSheets[1].cssRules[5].style.visibility='hidden';
                    document.styleSheets[1].cssRules[7].style.visibility='hidden';
                    fLowlist = false;
                }
            },

            setParams = function(destination) 
            // pass the sort option and the now value to the help screen
            {
                var test5=decodeURIComponent(destination);
                location.assign(test5);
            }

            getParams = function()
            {    
                var params = location.search.substring(1);

                var temp = params.split(',');
                if (temp[0] == 1) 
                {
                    var goback= temp[2];
                    var destination = escape(goback)+".html?1,"+temp[1].toString()+","+temp[3].toString()+","+temp[4];
                    var test5 = decodeURIComponent(destination);
                    location.assign(test5);
                }
                else {
                    //document.getElementById('backbutton').setAttribute("href","javascript:history.back();");
                    //document.getElementById('backbutton').removeAttribute('onclick');
                    window.history.back();
                }
            };
            -->
        </script>
    </head>
    <body id="detailPage" bgproperties="fixed" bgcolor="#000000" onloadset="play" topmargin="0" leftmargin="0" focustext="#ffffff" background="<?php echo plexGetImage($xmlMetaData->Video['art'], 1280, 720, 'backdrops/movies/') ?>">
        <table height="720" border="0" cellspacing="0" cellpadding="0" width="1280">
            <tr>
                <td width="1280">
                    <table height="720" border="0" cellspacing="0" cellpadding="0" width="1280">
                        <tr>
                            <td width="1187" valign="top" height="340">
                                <table border="0" cellspacing="0" cellpadding="0" width="1187">
                                    <tr>
                                        <td width="70" background="<?php echo $thumbOverlay ?>html/custom_header.png"/>
                                        <td valign="center" height="50" width="432" class="tvtt" background="<?php echo $thumbOverlay ?>html/custom_header.png"><?php echo $xmlMetaData->Video['title'] ?></td>
                                        <td align="center" valign="center" height="50" width="35" class="tvtts" background="<?php echo $thumbOverlay ?>html/custom_header.png">
                                            <img src="<?php echo plexGetImage($xmlMetaData['mediaTagPrefix'] . 'contentRating/' . $xmlMetaData->Video['contentRating'] . '?t=' . $xmlMetaData['mediaTagVersion'], 95, 35, 'movies/details/studios/') ?>"/>
                                        </td>
                                        <td align="center" valign="center" height="50" class="tvtt" background="<?php echo $thumbOverlay ?>html/custom_header.png" width="95">
                                            <img src="<?php echo plexGetImage($xmlMetaData['mediaTagPrefix'] . 'studio/' . $xmlMetaData->Video['studio'] . '?t=' . $xmlMetaData['mediaTagVersion'], 95, 35, 'movies/details/studios/') ?>"/>
                                        </td>
                                        <td align="center" valign="center" height="50" width="70" class="tvtts" background="<?php echo $thumbOverlay ?>html/custom_header.png"><?php echo $xmlMetaData->Video['year'] ?></td>
                                        <td valign="center" height="50" width="260" background="<?php echo $thumbOverlay ?>html/custom_header.png" class="rating">
                                            <img src="pictures/detail/rating_60.png"/> (<?php echo $xmlMetaData->Video['rating'] ?>/10)</td>
                                    </tr>
                                </table>
                            </td>
                            <td width="93" align="left" valign="middle" rowspan="2" height="720" background="<?php echo $thumbOverlay ?>html/custom_header-right.png">
                                <?php $playPath = $config['plex_url'] . urldecode($xmlMetaData->Video->Media->Part['key']); ?>
                                <a class="link" href="<?php echo $playPath ?>" onkeydownset="pgdn" onkeyupset="pgup" onkeyrightset="pgdn" onkeyleftset="pgup" TVID="Play" name="play" id="play" vod="">
                                    <img src="<?php echo $thumbOverlay ?>html/1x688.png" onfocussrc="<?php echo $thumbOverlay ?>html/1x688.png"/>
                                </a>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <table id="lowlist" width="1187" height="300" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <td width="250" height="300" valign="top" align="right" background="<?php echo $thumbOverlay ?>html/custom_tvbg-mov-l_dim.png">
                                            <table width="342" height="300" border="0" cellspacing="0" cellpadding="0">
                                                <tr>
                                                    <td width="52" height="300" rowspan="3"/>
                                                    <td width="310" height="332" align="center" valign="bottom">
                                                        <img width="224" src="<?php echo plexGetImage($xmlMetaData->Video['thumb'], 224, 331, 'posters/movies/') ?>"/>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td height="12"/>
                                                </tr>
                                            </table>

                                        </td>
                                        <td>
                                            <table height="290" border="0" cellspacing="0" cellpadding="0">
                                                <tr>
                                                    <td height="75"/>
                                                </tr>
                                                <tr>
                                                    <td colspan="2" height="250" valign="top" background="<?php echo $thumbOverlay ?>html/custom_tvbg-r_dim.png">
                                                        <table border="0" cellspacing="0" cellpadding="0" width="845" height="300">
                                                            <tr>
                                                                <td height="200" width="426" valign="top">
                                                                    <table border="0" cellspacing="0" cellpadding="0">
                                                                        <tr>
                                                                            <td height="30" valign="center">
                                                                                <table id="watchbar" height="30" valign="center">
                                                                                    <tr>
                                                                                        <td>
                                                                                            <img id="imgPlot" src="<?php echo $thumbOverlay ?>html/imgPloton.png" height="12"/>
                                                                                        </td>
                                                                                    </tr>
                                                                                </table>
                                                                            </td>
                                                                        </tr>
                                                                        <tr>
                                                                            <td height="135" valign="top" id="gtPlot" class="plot"><?php echo substr($xmlMetaData->Video['summary'], 0, 310) ?></td>
                                                                        </tr>
                                                                    </table>
                                                                    <table border="0" cellspacing="0" cellpadding="0" height="30">
                                                                        <tr>
                                                                            <td>
                                                                                <img src="<?php echo $thumbOverlay ?>html/1x688.png" height="30"/>
                                                                            </td>
                                                                            <td class="plot" width="40">
                                                                                <img src="<?php echo $thumbOverlay ?>html/duration.png" height="25"/>
                                                                            </td>
                                                                            <?php
                                                                            $milli = $xmlMetaData->Video->Media['duration'];
                                                                            $hrs = floor($milli / (1000 * 60 * 60));
                                                                            $min = floor(($milli % (1000 * 60 * 60)) / (1000 * 60));
                                                                            if ($hrs > 0) {
                                                                                $strTime = $hrs . 'h ' . $min . 'm';
                                                                            } else {
                                                                                $strTime = $min . 'm';
                                                                            }
                                                                            ?>
                                                                            <td height="30" class="gray" valign="middle" width="200"><?php echo $strTime ?></td>
                                                                            <td height="30" width="130"/>
                                                                            <td width="50" valign="top" align="right" id="pages" class="plotpage" height="12"> 1 / 2</td>
                                                                        </tr>
                                                                    </table>
                                                                    <table border="0" cellspacing="0" cellpadding="0" height="40">
                                                                        <tr>
                                                                            <td>
                                                                                <img src="<?php echo $thumbOverlay ?>html/1x688.png" height="40"/>
                                                                            </td>
                                                                            <td class="plot" width="40" height="30">
                                                                                <img src="<?php echo $thumbOverlay ?>html/subtitles.png"/>
                                                                            </td>
                                                                            <td class="normal">NO</td>
                                                                            <td width="30" align="center" class="gray"> | </td>
                                                                            <td class="plot" width="40">
                                                                                <img src="<?php echo $thumbOverlay ?>html/audio.png" height="24"/>
                                                                            </td>
                                                                            <td height="40" class="gray" valign="middle">MP3</td>
                                                                        </tr>
                                                                    </table>
                                                                </td>
                                                                <td valign="top">
                                                                    <table border="0" cellspacing="10" cellpadding="0">
                                                                        <tr>
                                                                            <td>
                                                                                <table border="0" cellspacing="0" cellpadding="0" width="406">
                                                                                    <tr>
                                                                                        <td class="gray" width="130">DIRECTED BY</td>
                                                                                        <td width="10"/>
                                                                                        <td width="266" class="plot"><?php echo $xmlMetaData->Video->Director['tag'] ?></td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td height="9" colspan="3">
                                                                                            <img src="<?php echo $thumbOverlay ?>html/hor-div-406.png"/>
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td valign="top" class="gray">STARRING</td>
                                                                                        <td width="10"/>
                                                                                        <td>
                                                                                            <?php
                                                                                            $i = 0;
                                                                                            foreach ($xmlMetaData->Video->Role as $person) {
                                                                                                $i++;
                                                                                                echo '<table border="0" cellpadding="0" cellspacing="0">';
                                                                                                echo '<tr>';
                                                                                                echo '<td class="plot"><a href="?destination=' . $_GET['destination'] . '&page=wall&key=' . $_SESSION['key'] . '&category=actor&filter=' . $person['id'] . '&index=1" >' . $person['tag'] . '</a></td>';
                                                                                                echo '</tr>';
                                                                                                echo '</table>';
                                                                                                if ($i == 6)
                                                                                                    break;
                                                                                            }
                                                                                            ?>
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td height="9" colspan="3">
                                                                                            <img src="<?php echo $thumbOverlay ?>html/hor-div-406.png"/>
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td class="gray">GENRE</td>
                                                                                        <td width="10"/>
                                                                                        <td class="plot">
                                                                                            <?php
                                                                                            $i = 0;
                                                                                            foreach ($xmlMetaData->Video->Genre as $Genre) {
                                                                                                $i++;
                                                                                                $genres = $genres . ' / ' . $Genre['tag'];
                                                                                                if ($i == 4)
                                                                                                    break;
                                                                                            }
                                                                                            $genres = ltrim($genres, ' /');
                                                                                            echo $genres;
                                                                                            ?>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td height="9" colspan="3">
                                                                                            <img src="<?php echo $thumbOverlay ?>html/hor-div-406.png"/>
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td class="gray">LIBRARY</td>
                                                                                        <td width="10"/>
                                                                                        <td class="plot">Movies</td>
                                                                                    </tr>
                                                                                </table>
                                                                            </td>
                                                                        </tr>
                                                                    </table>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td height="55" colspan="2" align="left">
                                                                    <table border="0" cellspacing="0" cellpadding="0">
                                                                        <tr>
                                                                            <td>
                                                                                <img src="<?php echo plexGetImage($xmlMetaData['mediaTagPrefix'] . 'videoCodec/' . $xmlMetaData->Video->Media['videoCodec'] . '?t=' . $xmlMetaData['mediaTagVersion'], 95, 35, 'movies/details/flags/') ?>"/>
                                                                                <img src="<?php echo plexGetImage($xmlMetaData['mediaTagPrefix'] . 'audioCodec/' . $xmlMetaData->Video->Media['audioCodec'] . '?t=' . $xmlMetaData['mediaTagVersion'], 95, 35, 'movies/details/flags/') ?>"/>
                                                                                <img src="<?php echo plexGetImage($xmlMetaData['mediaTagPrefix'] . 'audioChannels/' . $xmlMetaData->Video->Media['audioChannels'] . '?t=' . $xmlMetaData['mediaTagVersion'], 95, 35, 'movies/details/flags/') ?>"/>
                                                                                <img src="<?php echo plexGetImage($xmlMetaData['mediaTagPrefix'] . 'videoResolution/' . $xmlMetaData->Video->Media['videoResolution'] . '?t=' . $xmlMetaData['mediaTagVersion'], 95, 35, 'movies/details/flags/') ?>"/>
                                                                                <img src="<?php echo plexGetImage($xmlMetaData['mediaTagPrefix'] . 'videoFrameRate/' . $xmlMetaData->Video->Media['videoFrameRate'] . '?t=' . $xmlMetaData['mediaTagVersion'], 95, 35, 'movies/details/flags/') ?>"/>
                                                                                <img src="<?php echo plexGetImage($xmlMetaData['mediaTagPrefix'] . 'aspectRatio/' . $xmlMetaData->Video->Media['aspectRatio'] . '?t=' . $xmlMetaData['mediaTagVersion'], 95, 35, 'movies/details/flags/') ?>"/>
                                                                            </td>
                                                                        </tr>
                                                                    </table>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td colspan="2" valign="top"/>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </table>

                                        </td>
                                    </tr>
                                </table>

                            </td>
                        </tr>
                    </table>

                </td>
                <td valign="top" align="right"/>
            </tr>
        </table>
        <img src="<?php echo $thumbOverlay ?>boxes/dvd.png" id="Box_Overlay__LowList_NMT_and_PC__TV_PC"/>
        <img src="<?php echo $thumbOverlay ?>html/custom_tvbg-mov-r_dim-gap.png" id="tvbgmovr"/>
    </body>
    <a TVID="RED" href="#play" onclick="pageUp()"/>
    <a TVID="GREEN" href="#play" onclick="pageDown()"/>
    <a TVID="LEFT" href="#play" onclick="clickLeft()"/>
    <a TVID="RIGHT" href="#play" onclick="clickRight()"/>
    <a TVID="TAB" href="#play" onclick="toggleWatchbar()"/>
    <a TVID="INFO" href="#play" onclick=""/>
    <a TVID="HOME" href="../index.htm"/>
    <a TVID="PGDN" ONFOCUSLOAD="" name="pgdn" href="Being%20Human.S01E01.Episode%201.html"/>
    <a TVID="PGUP" ONFOCUSLOAD="" name="pgup" href="Beautiful%20Kate%20%282009%29.DvDRip.html"/>
</html>
<?php
$logger->info('Memory Usage: ' . Memory_Usage());
$logger->info('End=======================================movie details page=======================================End');
?>
